﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MedicService.Domain.Generic;
using MedicService.Server.Exception;

namespace MedicService.Domain.Print.Template {
    public class ActiveTemplate : Entity {
        private PrintTemplateInvoice invoiceTemplate;
        private PrintTemplate<PrintOrder> orderTemplate;
        private PrintTemplate<PrintExtract> extractTemplate;
        private PrintTemplate<PrintSertificate> sertificateTemplate;
        private PrintTemplate<PrintAttestatProtocol> attestatProtocolTemplate;
        private PrintTemplate<PrintProfileProtocol> profileProtocolTemplate;

        public PrintTemplateInvoice InvoiceTemplate {
            get { return checkExist(invoiceTemplate); }
            set { invoiceTemplate = value; }
        }

        public PrintTemplate<PrintOrder> OrderTemplate {
            get { return checkExist(orderTemplate); }
            set { orderTemplate = value; }
        }

        public PrintTemplate<PrintExtract> ExtractTemplate {
            get { return checkExist(extractTemplate); }
            set { extractTemplate = value; }
        }

        public PrintTemplate<PrintSertificate> SertificateTemplate {
            get { return checkExist(sertificateTemplate); }
            set { sertificateTemplate = value; }
        }

        public PrintTemplate<PrintAttestatProtocol> AttestatProtocolTemplate {
            get { return checkExist(attestatProtocolTemplate); }
            set { attestatProtocolTemplate = value; }
        }

        public PrintTemplate<PrintProfileProtocol> ProfileProtocolTemplate {
            get { return checkExist(profileProtocolTemplate); }
            set { profileProtocolTemplate = value; }
        }

        private T checkExist<T>(T entity) where T : Entity{
            if (entity == null || entity.Id <= 0) {
                throw new PrintTemplateException();
            }
            return entity;
        }

    }
}